﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using VisionRoc.Core;

namespace VisionRoc_Measure
{
    public partial class FormPanasonicTool : Form
    {
        PanasonicMewtocol m_PanasonicMewtocol;
        public FormPanasonicTool(PanasonicMewtocol _PanasonicMewtocol)
        {
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景 
            SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲  
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            InitializeComponent();
            m_PanasonicMewtocol = _PanasonicMewtocol;
        }

        private void FormPanasonicTool_Load(object sender, EventArgs e)
        {
            m_PanasonicMewtocol.LoadSerialPort(Combox_COM, Combox_Paud, Combox_Parity, Combox_StopBits, Combox_DataBits);
            //判断串口是否已经打开
            if (m_PanasonicMewtocol.PLC != null)
            {
                if (m_PanasonicMewtocol.PLC.IsOpen())
                {
                    m_PanasonicMewtocol.ReadParameter();
                    Combox_COM.Text = m_PanasonicMewtocol.COM.ToString();
                    Combox_Paud.Text = m_PanasonicMewtocol.BaudRate.ToString();
                    Combox_Parity.Text = m_PanasonicMewtocol.BarityBit.ToString();
                    Combox_DataBits.Text = m_PanasonicMewtocol.DataBits.ToString();
                    Combox_StopBits.Text = m_PanasonicMewtocol.StopBits.ToString();
                }
                else
                {
                   
                }
            }
            else
            {
                
            }
        }

        private void btn_Set_Click(object sender, EventArgs e)
        {
            try
            {
                m_PanasonicMewtocol.COM = this.Combox_COM.Text;
                m_PanasonicMewtocol.BaudRate =Convert.ToInt32( this.Combox_Paud.Text);
                m_PanasonicMewtocol.DataBits = Convert.ToInt32(this.Combox_DataBits.Text);
                m_PanasonicMewtocol.BarityBit = Convert.ToInt32(this.Combox_Parity.Text);
                m_PanasonicMewtocol.StopBits = Convert.ToInt32(this.Combox_StopBits.Text);
                m_PanasonicMewtocol.WriteParameter();
                MessageBox.Show("保存成功！");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}
